package com.zyf.chapter01.principle.SOLID.OCP.handler;

import com.zyf.chapter01.principle.SOLID.OCP.AlertRule;
import com.zyf.chapter01.principle.SOLID.OCP.ApiStatInfo;
import com.zyf.chapter01.principle.SOLID.OCP.Notification;
import com.zyf.chapter01.principle.SOLID.OCP.NotificationEmergencyLevel;

/**
 * 接口错误处理类
 * @author yifeng
 */
public class ErrorAlertHandler extends AlertHandler {
    public ErrorAlertHandler(AlertRule rule, Notification notification) {
        super(rule, notification);
    }

    @Override
    public void check(ApiStatInfo apiStatInfo) {
        // 接口错误次数超过允许的最大值，则通知负责人或团队
        if(apiStatInfo.getErrorCount() >
                rule.getMatchedRule(apiStatInfo.getApi()).getMaxErrorCount()) {
            notification.notify(NotificationEmergencyLevel.SEVERE, "...");
        }
    }
}
